//
//  EncryptMgr.m
//  carcareIOS
//
//  Created by ileo on 16/7/25.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "EncryptMgr.h"
#import "NSString+Encode.h"

#define CODE @"3a06ca92e95705e1"

@implementation EncryptMgr

+(NSString *)sortAndSpliceWithParams:(NSDictionary *)params{
    NSArray *keys = [[params allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
        return [obj1 compare:obj2 options:NSLiteralSearch];
    }];
    NSMutableString *string = [NSMutableString stringWithCapacity:10];
    for (int i = 0; i < keys.count; i++) {
        NSString *key = keys[i];
        if (i != 0) [string appendString:@"&"];
        if ([[NSString stringWithFormat:@"%@",params[key]] isNotNil]) {
            [string appendFormat:@"%@=%@",key,params[key]];
        }
    }
    return string;
}

+(NSString *)encryptWithString:(NSString *)string{
    NSString *md5 = [[NSString stringWithFormat:@"%@%@",string,CODE] encodeWithMD5];
    return md5;
}

@end
